package com.yourname.myapplication.ieportQuestions

import android.content.Context
import android.os.Environment
import com.google.gson.Gson
import com.yourname.myapplication.data.model.Question
import java.io.File
import java.io.FileWriter

fun exportQuestions(context: Context, questions: List<Question>) {
    val gson = Gson()
    val json = gson.toJson(questions)

    val externalFilesDir = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
    val file = File(externalFilesDir, "questions.json")

    try {
        val writer = FileWriter(file)
        writer.write(json)
        writer.close()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}